﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BO.Admin;
using Channelvn.Cached.Common;
using BAL;
using System.Configuration;

namespace ProjectQuaDep
{
    public partial class Detail : System.Web.UI.Page
    {
        protected DataTable dtDetail = new DataTable();
        protected DataTable dtOther = new DataTable();
        protected string linkImgBig = "", linkImgCrop = "";
        protected string linkCm = "";
        protected string linkRL = "";
        protected string linkRR = "";
        protected string NameBig = "";
        protected string sn = "";
        protected string vote = "0";
        protected string id = "0";
        protected string sHttp = BO.Const.sHttpDomain;
        protected string imageid = "0";
        protected string ShortContent = "";
        protected string index = "0";

        protected void Page_Load(object sender, EventArgs e)
        {

            imageid = Request.QueryString["imagesid"].ToString();
            index = Request.QueryString["index"].ToString();
            dtDetail = ImagesBO.GetInfomationImagesBO(imageid);
            Page.RegisterHiddenField("#hdPageType", Lib.QueryString.PageType.ToString());
            string name = dtDetail.Rows[0][BO.Const.tbImages.Name].ToString();
            dtOther = ImagesBO.getAllImagesOther(name, "79", imageid);
            int countOther = dtOther.Rows.Count;
            //tinh toan
            int iNext = int.Parse(index) + 1;
            if (iNext > countOther)
            {
                iNext = int.Parse(index);//neu nho hon thi dung lai 
            }
            int iBack = int.Parse(index) - 1;
            if (iBack < 0)
            {
                iBack = int.Parse(index);
            }
            if (index == "0")
            {
                if (dtDetail.Rows.Count > 0)
                {
                    //thong tin
                    sn = DateTime.ParseExact(dtDetail.Rows[0][BO.Const.tbImages.Birthday].ToString(), "yyyyMMdd", null).ToString("yyyy");
                    NameBig = dtDetail.Rows[0][BO.Const.tbImages.Name].ToString();

                    vote = dtDetail.Rows[0][BO.Const.tbImages.LikeWeb].ToString();
                    id = imageid;
                    ShortContent = dtDetail.Rows[0][BO.Const.tbImages.ShortContent].ToString();
                    //
                    linkImgBig = dtDetail.Rows[0][BO.Const.tbImages.Img].ToString();
                    linkImgCrop = dtDetail.Rows[0][BO.Const.tbImages.ImgThumb].ToString();
                    //link cm fb
                    //linkCm = "http://khodep.com/Products/NewProductDetail.aspx?id=" + imageid;
                    linkCm = sHttp + BO.Utils.BuildLinkDetail(name, id, "0");

                    Utils.SetPageHeader(this.Page, NameBig, "", "");
                    string newsURLFormat = ConfigurationManager.AppSettings["Domain"].ToString() + "/{0}-i{1}id{2}.htm";
                    string news_url = string.Format(newsURLFormat, Utils.UnicodeToKoDauAndGach(NameBig).Replace("\"", "").Replace("'", ""), id, index);
                    Utils.Set_Page_FB(this.Page, news_url, NameBig + "_" + id, ConfigurationManager.AppSettings["Domain"] + linkImgCrop, ShortContent);
                }
            }
            else
            {
                if (countOther > 0)
                {
                    int iIndex = int.Parse(index) - 1;//vi no bat nguon tu` k ma index =1 phai tru di 1 moi =0
                    linkImgBig = dtOther.Rows[iIndex][BO.Const.tbImages.Img].ToString();
                    linkImgCrop = dtOther.Rows[iIndex][BO.Const.tbImages.ImgThumb].ToString();
                    //thong tin
                    sn = DateTime.ParseExact(dtDetail.Rows[0][BO.Const.tbImages.Birthday].ToString(), "yyyyMMdd", null).ToString("yyyy");
                    NameBig = dtOther.Rows[iIndex][BO.Const.tbImages.Name].ToString();
                    vote = dtOther.Rows[iIndex][BO.Const.tbImages.LikeWeb].ToString();
                    id = dtOther.Rows[iIndex][BO.Const.tbImages.ImageId].ToString();
                    ShortContent = dtOther.Rows[iIndex][BO.Const.tbImages.ShortContent].ToString();
                    //link cm fb
                    //linkCm = "http://khodep.com/Products/NewProductDetail.aspx?id=" + dtOther.Rows[iIndex][BO.Const.tbImages.ImageId].ToString();
                    linkCm = sHttp + BO.Utils.BuildLinkDetail(NameBig, id, "0");

                    Utils.SetPageHeader(this.Page, NameBig, "", "");
                    string newsURLFormat = ConfigurationManager.AppSettings["Domain"].ToString() + "/{0}-i{1}id{2}.htm";
                    string news_url = string.Format(newsURLFormat, Utils.UnicodeToKoDauAndGach(NameBig).Replace("\"", "").Replace("'", ""), id, index);
                    Utils.Set_Page_FB(this.Page, news_url, NameBig + "_" + id, ConfigurationManager.AppSettings["Domain"] + linkImgCrop, ShortContent);
                }
            }
            //link tien lui
            linkRL = BO.Utils.BuildLinkDetail(name, imageid, iBack.ToString());//"/Detail.aspx?imagesid=8&index=" + iBack;
            linkRR = BO.Utils.BuildLinkDetail(name, imageid, iNext.ToString());//"/Detail.aspx?imagesid=8&index=" + iNext;
        }
    }
}